package org.nanotek.mq.listener;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.ObjectMessage;
import org.apache.log4j.Logger;
import org.nanotek.Base;
import org.nanotek.Dispatcher;

public class QueueListenerDispatcher<T extends Base<?>> extends
		QueueListener<T> implements Dispatcher<T> {
	
	Logger log = Logger.getLogger(QueueListenerDispatcher.class);
	public QueueListenerDispatcher() {
	}
	

	@Override
    @SuppressWarnings("unchecked")
	public void onMessage( final Message message )
    {
       
        	ObjectMessage messageObject = (ObjectMessage)message; 
        	T base;
			try {
				base = (T) messageObject.getObject();
	        	System.err.println("Message Object Received " + base.getId());
	        	dispatch(base);
			} catch (JMSException e) {
				e.printStackTrace();
				log.debug("Message Listener Not property configured.");
			}
    }

	@Override
	public void dispatch(T data) {
		log.debug("dispatch Base Class " + data.getClass().getName());
	}

}
